﻿using System.Windows;
using Tfs.OnTheRoad.Helpers;
namespace Tfs.OnTheRoad.Commands
{
    /// <summary>
    /// Removes an Access Profile
    /// </summary>
    public class RemoveProfileCommand : BaseCommand
    {
        public override void Execute(object parameter)
        {
            string name = App.SettingsViewModel.ProfileName;
            if (MessageBox.Show(string.Format("Do you really want to delete the Profile {0}?", name), "Remove Profile", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                App.SettingsViewModels.Remove(App.SettingsViewModel);
                //The we save
                // Save the valid credentials in the Isolated Storage
                SettingsStorageHelper.ClearSettings(App.IsolatedStorageFileName);
                SettingsStorageHelper.SaveSettings(App.SettingsViewModels, App.IsolatedStorageFileName);
                if (App.SettingsViewModels.Count==0)
                    //If there's no more, we need to add a new
                    NavigateTo("/Pages/SettingsPage.xaml?Add=1");      
            }
        }
    }
}